


import 'package:valovault_reminder/common/ui/val_base_ui_kit_root.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'dart:io';
import 'package:webview_flutter_wkwebview/webview_flutter_wkwebview.dart';

class ValWebViewController extends StatefulWidget {
  final String url;
  final String title;
  const ValWebViewController(this.url,{this.title = '',super.key});

  @override
  State<ValWebViewController> createState() => _ValWebViewControllerState();
}

class _ValWebViewControllerState extends State<ValWebViewController> {

  late final WebViewController controller;
  final PlatformWebViewControllerCreationParams params = PlatformWebViewControllerCreationParams();

  void _initWebController() {
    controller = WebViewController.fromPlatformCreationParams(params);
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _initWebController();
    print(widget.url);
    controller.loadRequest(Uri.parse(widget.url));
  }


  @override
  Widget build(BuildContext context) {
    return ValBaseUIKitRoot(
        WebViewWidget(
          controller: controller,
          gestureRecognizers: {
            if (Platform.isAndroid) Factory(() => LongPressGestureRecognizer()),
          },
        ),
      titleStr: widget.title ,
    );
  }
}

